package com.personnel.controller;

import com.personnel.pojo.LeaveRequest;
import com.personnel.service.LeaveRequestService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (LeaveRequest)表控制层
 *
 * @author yuepeng
 * @since 2022-02-23 10:53:04
 * @version 1.0
 */
@RestController
@RequestMapping("/leaveRequest")

public class LeaveRequestController {
    /**
     * 服务对象
     */
    @Resource
    private LeaveRequestService leaveRequestService;

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @param staffName  模糊查询的内容
     * @param status  模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)

    public Map<String, Object> selectForPage(@RequestParam(name = "page") int index,int limit, String staffName, Integer status) {
        return this.leaveRequestService.selectForPage(index, limit, staffName, status);
    }
    
    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public Map<String, Object> selectAll() {
        return this.leaveRequestService.selectAll();
    }
    
    /**
     * 通过主键删除单条数据
     *
     * @param leaveRequestId 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public Map<String, Object> deleteById(@RequestParam("leaveRequestId") String leaveRequestId) {
        return this.leaveRequestService.deleteById(leaveRequestId);
    }
    
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public Map<String, Object> selectById(Integer id) {
        return this.leaveRequestService.selectById(id);
    }
    
    /**
     * 通过主键更新单条数据
     *
     * @param leaveRequest 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public Map<String, Object> updateById(@RequestBody LeaveRequest leaveRequest) {
        return this.leaveRequestService.updateById(leaveRequest);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param leaveRequest 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Map<String, Object> insert(@RequestBody LeaveRequest leaveRequest) {
        return this.leaveRequestService.insert(leaveRequest);
    }

}